package com.seeyon.ctp.rest.resources;

import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.service.SRMKanBanDataIPDService;
import com.seeyon.apps.brwh.service.SencondDatailService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.log.CtpLogFactory;
import org.apache.commons.logging.Log;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取SRM地图数据
 */
@Path("jssdk/SRMKB")
public class SRMKanBanDataIPDResources extends BaseResource {

    private static final Log LOG = CtpLogFactory.getLog(SRMKanBanDataIPDResources.class);

    private SRMKanBanDataIPDService sRMKanBanDataIPDService = (SRMKanBanDataIPDService) AppContext.getBean("sRMKanBanDataIPDService");

    @Path("getDiTuDataList")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getDiTuDataList(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<Map<String, Object>> diTuDataList = sRMKanBanDataIPDService.getDiTuDataList();
            map.put("code","200");
            map.put("data",diTuDataList);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM地图数据-获取地图区域数据异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM地图数据-获取地图区域数据异常");
        }

        return this.ok(JSONObject.toJSONString(map));
    }

    @Path("getDataList")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getDataList(Map<String,Object> parm){
        HashMap<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> diTuDataList = sRMKanBanDataIPDService.getDataList(parm.get("quName").toString(),parm.get("type").toString());
            map.put("code","200");
            map.put("data",diTuDataList);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM地图数据-获取区域详情数据列表异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM地图数据-获取区域详情数据列表异常");
        }

        return this.ok(JSONObject.toJSONString(map));
    }

    @Path("getMoreUrl")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getMoreUrl(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> diTuDataList = sRMKanBanDataIPDService.getMoreUrl();
            map.put("code","200");
            map.put("data",diTuDataList);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM地图数据-更多url地址异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM地图数据-更多url地址异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }


    @Path("getCggcsgzztData")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCggcsgzztData(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            ArrayList<Map<String, Object>> cggcsgzztData = sRMKanBanDataIPDService.getCggcsgzztData();
            map.put("code","200");
            map.put("data",cggcsgzztData);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM采购工程师工作状态数据异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM采购工程师工作状态数据异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }

    @Path("getZjbjeData")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getZjbjeData() throws BusinessException, SQLException {
        Map<String, Object> zjbjeMapData = sRMKanBanDataIPDService.getZjbjeMapData();
        return this.ok(zjbjeMapData);
    }

    @Path("getJblData")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getJblData() throws BusinessException, SQLException {
        Map<String, Object> jblMapData = sRMKanBanDataIPDService.getJblData();
        return this.ok(jblMapData);
    }

    @Path("getCgzygzztData")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCgzygzztData(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            ArrayList<Map<String, Object>> cggcsgzztData = sRMKanBanDataIPDService.getCgzygzztData();
            map.put("code","200");
            map.put("data",cggcsgzztData);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM采购专员工作状态数据异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM采购专员工作状态数据异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }

    @Path("getCgkshDataOne")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCgkshDataOne(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> cgkshDataOne = sRMKanBanDataIPDService.getCgkshGhzqData();
            map.put("code","200");
            map.put("data",cgkshDataOne);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM采购可视化供货周期数据异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM采购可视化供货周期数据异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }


    @Path("getCgxqWlJdData")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCgxqWlJdData(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<Map<String, Object>> cgxqWlJdData = sRMKanBanDataIPDService.getCgxqWlJdData();
            map.put("code","200");
            map.put("data",cgxqWlJdData);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM采购可视化采购需求物料进度数据异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM采购可视化采购需求物料进度数据异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }


    @Path("getCgkshMoreUrl")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getCgkshMoreUrl(){
        HashMap<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> diTuDataList = sRMKanBanDataIPDService.gerCgkshGdDataListUrl();
            map.put("code","200");
            map.put("data",diTuDataList);
            map.put("msg","");
        }catch (Exception e){
            LOG.info("获取SRM采购可视化-更多url地址异常：",e);
            map.put("code","500");
            map.put("data",null);
            map.put("msg","获取SRM采购可视化-更多url地址异常");
        }
        return this.ok(JSONObject.toJSONString(map));
    }

    @Path("getTest")
    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces({ MediaType.APPLICATION_JSON })
    public Response getTest(){
        return this.ok(JSONObject.toJSONString(sRMKanBanDataIPDService.getCgkshGhzqDataTest()));
    }

}
